<template>
    <div class="pad">
        <!-- table start -->
        <tableDataEl
                :page.sync="page"
                :pageSize.sync="pageSize"
                :tableData="tableData.list"
                :tableLabel="tableLabel"
                height="89vh"
                :pageCount="tableData.rows"
                v-loading="loading"
                @handleDetail="handleDetail"
        />
        <!-- table end -->

        <!-- dialog start -->
        <el-dialog
                :visible.sync="isShowDialog"
                center
                title="物料详情"
                width="40%"
                v-el-drag-dialog
        >
            <div class="detail" v-loading="detailLoading">
                <el-table
                        :data="detailData.list"
                        border
                >
                    <el-table-column
                            label="物料名称"
                            prop="materiel"
                            align="center"
                            width="200"
                    />
                    <el-table-column
                            label="数量L"
                            prop="num"
                            align="center"
                    />
                    <el-table-column
                            label="备注"
                            prop="remarks"
                            align="center"
                            width="250"
                    />
                </el-table>
                <el-form>
                    <el-form-item label="详细地址:">
                        {{address}}
                    </el-form-item>
                </el-form>
                <div class="btns" style="text-align:center;">
                    <el-button type="primary" @click="print">打印</el-button>
                </div>
            </div>
        </el-dialog>
        <!-- dialog end -->
    </div>
</template>

<script>
    import tableDataEl from '@/views/Setup/common/table'
    export default {
        name: "rejected",
        components: {
            tableDataEl
        },
        data () {
            return {
                page: 1,
                pageSize: 8,
                tableData: {},
                tableLabel: [
                    {
                        label: '运营商名称',
                        prop: 'company'
                    },
                    {
                        label: '负责人',
                        prop: 'leader'
                    },
                    {
                        label: '电话',
                        prop: 'phone'
                    },
                    {
                        label: '申请时间',
                        prop: 'create_time'
                    },
                    {
                        label: '驳回时间',
                        prop: 'audit_time'
                    },
                    {
                        label: '驳回理由',
                        prop: 'reason'
                    },
                    {
                        label: '审核人',
                        prop: 'audit_person'
                    },
                    {
                        label: '物料详情',
                        detail: true,
                        btnText: '查看',
                        methodName: 'handleDetail'

                    }
                ],
                loading: false,
                isShowDialog: false,
                detailLoading: false,
                detailData: {},
                address: '',
                obj: {}
            }
        },
        methods: {
            async init () { //初始化
                this.loading = true;
                let res = await this.api.log_rejectList({page: this.page, pageSize: this.pageSize});
                res.code ? this.tableData = res.data : this.$message(res.msg);
                this.loading = false;
            },
            async handleDetail (...value) {
                this.isShowDialog = true;
                this.detailLoading = true;
                this.obj = {id: value[1]['id'], aid: value[1]['aid']};
                let res = await this.api.mateDetail({id: value[1]['id'],aid: value[1]['aid']});
                if(res.code) {
                    let address = res.data.address
                    this.detailData = res.data;
                    this.address = address['province'] + address['city'] + address['county'] + address['address'];
                }else this.$message(res.msg)
                this.detailLoading = false
            },
            async print () {
                window.location.href = `${process.env.VUE_APP_URL}auditAdmin/ExportExcel/agentExcel?id=${this.obj['id']}&aid=${this.obj['aid']}`
            }
        },
        mounted () {
            this.init();
        },
        watch: {
            page () {
                this.init();
            },
            pageSize () {
                this.init();
            }
        }
    }
</script>

<style scoped>
    .pad {
        padding:10px;
    }
    .el-form-item {margin-bottom:6px;}
</style>
